﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using System.Xml.Linq;
using WebSite.NewsHandle;
public partial class WebSite_News : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            NewsHandler newsHandler = new NewsHandler("Data Source=Localhost;Integrated Security=SSPI;Initial Catalog=CSHDB");
            if (Request["id"]!=null)
            {
                string ContentID = Request["id"].ToString();
                DataSet ds = newsHandler.GetNewsById(int.Parse(ContentID));
                if (ds.Tables[0].Rows.Count > 0)
                {
                    TitleLabel.Text = ds.Tables[0].Rows[0][0].ToString().Trim();   //文章标题
                    PostDateLabel.Text = "文章发布时间: " + ds.Tables[0].Rows[0][3].ToString().Trim(); //文章发布时间
                    ContentCatagoryLabel.Text = "[文章类别:" + ContentCatagory(ds.Tables[0].Rows[0][4].ToString().Trim()) + "]";
                    ContentInfoLabel.Text = ds.Tables[0].Rows[0][1].ToString();
                    SqlConnection conn = new SqlConnection("Data Source=Localhost;Integrated Security=SSPI;Initial Catalog=CSHDB");
                    conn.Open();
                    string sqlquiry = "select Name from UserDetail where UserId='" + ds.Tables[0].Rows[0][2].ToString()+"'";
                    SqlCommand command = new SqlCommand(sqlquiry, conn);
                    SqlDataReader reader = command.ExecuteReader();
                    if (reader.HasRows)
                    {
                        reader.Read();
                        AuthorLabel.Text = "作者: " + reader.GetValue(0).ToString().Trim();
                    }
                    conn.Close();
                }
                else
                {
                    ContentInfoLabel.Text = "<b>没有您所浏览的文章!</b>";
                }
            }
            else 
            {
                Response.Redirect("Default.aspx", false);
                HttpContext.Current.ApplicationInstance.CompleteRequest();
                return;
            }
            
        }
        catch (System.Exception ex)
        {
            ContentInfoLabel.Text = "<b>"+ex.Message+"</b>";
        }
       
    }
    private string ContentCatagory(string SectionId)
    {
        if (SectionId=="0")
        {
            return "新闻";
        }
        else if (SectionId=="1")
        {
            return "重要通知";
        }
        else if (SectionId=="2")
        {
            return "健康知识";
        }
        else
        {
            return "";
        }
    }
}
